package cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.mwgapplication;

import android.app.Application;
import android.content.ComponentName;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;

import com.blankj.utilcode.util.Utils;

import org.apache.http.cookie.Cookie;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.R;
import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.activitys.MainActivity;
import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.utils.Abstract;
import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.utils.Constance;

/**
 * Created by dell on 2017/10/30.
 */

public class WuhanMwgApplication extends Application {
    public static SharedPreferences sSharedPreferences;
    public static SharedPreferences.Editor sEditor;
    public static Abstract anAbstract = null;
    public static String strcookie="";


    public static List<Cookie> cookies;

    public static List<Cookie> getCookies() {
        return cookies != null ? cookies : new ArrayList<Cookie>();
    }

    public static void setCookies(List<Cookie> cookies) {
        WuhanMwgApplication.cookies = cookies;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        Utils.init(this);
        WuhanMwgApplication.sSharedPreferences = getSharedPreferences(Constance.SHARE_KEY, MODE_PRIVATE);
        WuhanMwgApplication.sEditor = WuhanMwgApplication.sSharedPreferences.edit();
        Resources resources1 = getApplicationContext().getResources();
        DisplayMetrics dm1 = resources1.getDisplayMetrics();
        Configuration config1 = resources1.getConfiguration();
        Locale locale1 = getApplicationContext().getResources().getConfiguration().locale;
        String language = sSharedPreferences.getString(Constance.language,"zh");
        if(language==null || language.equals("zh"))
        {
            locale1 = Locale.CHINA;
        }
        else if(language.equals("en"))
        {
            locale1 = Locale.ENGLISH;
        }
        else if(language.equals("fr"))
        {
            locale1 = Locale.FRANCE;
        }
        config1.setLocale(locale1);
        resources1.updateConfiguration(config1, dm1);
    }


}
